package com.ruoyi.generator.util;
import java.io.*;
import java.util.zip.*;
public class UnzipFile {
        public static void unzip(String zipFilePath, String destDirectoryPath) throws IOException {
            File destDirectory = new File(destDirectoryPath);
            if (!destDirectory.exists()) {
                destDirectory.mkdir();
            }

            FileInputStream fis = new FileInputStream(zipFilePath);
            ZipInputStream zipis = new ZipInputStream(new BufferedInputStream(fis));

            ZipEntry entry;
            byte[] buffer = new byte[1024];
            int count;

            while ((entry = zipis.getNextEntry()) != null) {
                String entryName = entry.getName();
                String entryPath = destDirectoryPath + File.separator + entryName;

                if (entry.isDirectory()) {
                    File dir = new File(entryPath);
                    dir.mkdir();
                } else {
                    FileOutputStream fos = new FileOutputStream(entryPath);
                    BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);

                    while ((count = zipis.read(buffer, 0, buffer.length)) != -1) {
                        bos.write(buffer, 0, count);
                    }

                    bos.flush();
                    bos.close();
                }
            }

            zipis.close();
            fis.close();
        }



    }
